﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JT_DrawSubArea.aspx.cs"
    Inherits="JTicket.UI.JT_DrawSubArea" %>
<%@ OutputCache Duration="1" Location="Any" NoStore="true" VaryByParam="*"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="Style/DrawStyle.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-cookie.js" type="text/javascript"></script>
    <script src="Scripts/JSTitle.js" type="text/javascript"></script>
    <script src="ColorPicker/dhtmlxcommon.js" type="text/javascript"></script>
    <script src="ColorPicker/dhtmlxcolorpicker.js" type="text/javascript"></script>
    <link href="ColorPicker/dhtmlxcolorpicker.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/JSCommon.js" type="text/javascript"></script>
    <script type="text/javascript">
        //执行左键按住
        var isBound = false;
        document.onmousedown = function () {
            if (event.button == 1) {
                isBound = true;
            }
        }
        document.onmouseup = function () {
            isBound = false;
        }
        window.onscroll = function () { isBound = false; }
        //禁止选中
        document.onselectstart = new Function("event.returnValue=false;");

        $(document).ready(
        function () {
            SeatGet();
        });

        function SaveSeat() {
            if ($("#rows").val() == "") { alert("请输入行数量"); return false; }
            if ($("#cows").val() == "") { alert("请输入列数量"); return false; }
            var IsHave = false;
            $.ajax({
                type: "get",
                url: "ExsitArea.axd?SubCode= " + $("#subcode").val() + "&Time=" + new Date(),
                success: function (Result) {
                    if (Result == "True") { IsHave = true; }
                    if (IsHave) {
                        var ok = confirm("此分区已存在座位信息,是否重新生成!")
                        if (!ok) {
                            return false;
                        }
                    }
                    $("#checkFlag").show();
                    var url = "DrawSeateHandler.axd?ex=" + $("#cows").val()
                                        + "&ey=" + $("#rows").val() + "&AreaCode="
                                        + SCode + "&subcode="
                                        + $("#subcode").val() + "&subname=" + $("#subname").val()
                                        + "&thcode=" + ThCode + "&Time=" + new Date();
                    $.ajax({
                        type: "get",
                        url: url,
                        success: function () {
                            alert("座位图生成成功！");
                            SeatGet();
                            $("#checkFlag").hide();
                        },
                        error: function () {
                            alert("座位图生成失败,请重新生成！");
                            $("#checkFlag").hide();
                        }
                    });
                },
                error: function () { },
                cach: false
            });
        }
        function Choose(e) {
            var div = e;
            var bColor = $(div).css("background-color");
            var bID = div.id;
            if (bColor == "#992c0a") {//已选
                var CodeArr = $.cookie('SeatCode').split('|');
                var ColorArr = $.cookie('SeatColor').split('|');
                for (var i = 0; i < CodeArr.length; i++) {
                    if ($.trim(CodeArr[i].replace('|', '')) == bID) {
                        $(div).css("background-color", ColorArr[i]);
                        ColorArr = ColorArr.del(i);
                        break;
                    }
                }
                $.cookie('SeatCode', $.trim($.cookie('SeatCode')).replace(bID + "|", $.trim(escape(""))));
                $.cookie('SeatColor', ColorArr.join("|"));

            } else {//未选
                $(div).css("background-color", "#992c0a");
                $.cookie('SeatCode', $.trim($.cookie('SeatCode')) + bID + '|');
                $.cookie('SeatColor', $.trim($.cookie('SeatColor')) + bColor + '|');
            }
        }
        //删除数组指定项
        Array.prototype.del = function (n) {
            if (n < 0)
                return this;
            else
                return this.slice(0, n).concat(this.slice(n + 1, this.length));
        }
        //颜色选择器
        function initColorPicker() {
            var myCP1 = new dhtmlXColorPickerInput('Color');
            myCP1.setImagePath("ColorPicker/imgs/");
            myCP1.init();
        }

        function SeatShow() {
            $.ajax({
                type: "get",
                url: "DrawShow.axd?SeatList=" + $.cookie('SeatCode') + "&SubCode="
                + $("#subcode").val() + "&Time=" + new Date(),
                success: function () {
                    SeatGet();
                    $("#checkFlag").hide();
                },
                error: function () {
                    $("#checkFlag").hide();
                }
            });
        }
        function SeatHide() {
            $.ajax({
                type: "get",
                url: "DrawHide.axd?SeatList=" + $.cookie('SeatCode') + "&SubCode="
                + $("#subcode").val() + "&Time=" + new Date(),
                success: function (Result) {
                    SeatGet();
                    $("#checkFlag").hide();
                },
                error: function () {
                    $("#checkFlag").hide();
                }
            });
        }
        function SeatGet() {
            $("#checkFlag").show();
            $.ajax({
                type: "get",
                url: "DrawGetHandler.axd?ThCode=" + ThCode + "&SubCode=" + $("#subcode").val() + "&Cow=" + $("#cows").val() + "&Time=" + new Date(),
                success: function (Result) {
                    document.getElementById('Seats').innerHTML = Result;
                    $.cookie('SeatCode', "");
                    $.cookie('SeatColor', "");
                    $("#checkFlag").hide();
                },
                error: function () {
                    $("#checkFlag").hide();
                }
            });

        }
        function DrawNote() {
            $("#checkFlag").show();
            $.ajax({
                type: "get",
                url: "DrawNote.axd?SeatList=" + $.cookie('SeatCode') + "&SubCode="
                + $("#subcode").val() + "&Note=" + $("#Note").val()
                + "&Time=" + new Date(),
                success: function (Result) {
                    SeatGet();
                    $("#checkFlag").hide();
                },
                error: function () {
                    $("#checkFlag").hide();
                }
            });
        }
        function DrawRow() {
            $("#checkFlag").show();
            $.ajax({
                type: "get",
                url: "DrawRow.axd?SeatList=" + $.cookie('SeatCode') + "&SubCode="
                + $("#subcode").val() + "&Row=" + $("#Row").val()
                + "&Time=" + new Date(),
                success: function () {
                    SeatGet();
                    $("#checkFlag").hide();
                },
                error: function (Result) {
                    $("#checkFlag").hide();
                }
            });
        }
        function DrawCow() {
            $("#checkFlag").show();
            $.ajax({
                type: "get",
                url: "DrawCow.axd?SeatList=" + $.cookie('SeatCode') + "&SubCode="
                + $("#subcode").val() + "&Cow=" + $("#Cow").val()
                + "&Time=" + new Date(),
                success: function () {
                    SeatGet();
                    $("#checkFlag").hide();
                },
                error: function () {
                    $("#checkFlag").hide();
                }
            });
        }
        function DrawMsg() {
            $("#checkFlag").show();
            $.ajax({
                type: "get",
                url: "DrawMsg.axd?SeatList=" + $.cookie('SeatCode') + "&SubCode="
                + $("#subcode").val() + "&Msg=" + $("#Msg").val()
                + "&Time=" + new Date(),
                success: function () {
                    SeatGet();
                    $("#checkFlag").hide();
                },
                error: function () {
                    $("#checkFlag").hide();
                }
            });
        }
        function DrawPriceColor() {
            if ($("#Color").val() == "") {
                alert("请选择票价颜色！");
                return false;
            }
            if ($("#ticketname").val() == "")
            { alert("请输入票类名称！"); return false; }
            if (!IsMoney($("#ticketprice").val())) {
                alert("票价金额错误！");
                return false;
            }
            $("#checkFlag").show();
            $.ajax({
                type: "get",
                url: "DrawPriceColor.axd?SeatList="
                + $.cookie('SeatCode') + "&SubCode="
                + $("#subcode").val()
                + "&Name=" + $("#ticketname").val()
                + "&Price=" + $("#ticketprice").val()
                + "&Color=" + $("#Color").val()
                + "&Time=" + new Date(),
                success: function () {
                    SeatGet();
                    $("#checkFlag").hide();
                },
                error: function () {
                    $("#checkFlag").hide();
                }
            });
        }
    </script>
</head>
<body oncontextmenu="return  false;" onload="initColorPicker();">
    <form id="form1" runat="server">
    <p id="checkFlag" style="filter: alpha(opacity=30); -moz-opacity: 0.3; opacity: 0.3;
        background-color: #000; width: 100%; height: 100%; z-index: 1000; position: absolute;
        left: 0; top: 0; display: none; overflow: hidden; text-align: center; color: Red;
        font-weight: bold; vertical-align: middle">
        数据处理中，请稍后...<br />
        <img alt="" src="Images/Loading-leng.gif" />
    </p>
    <div style="background-color: #ffffff">
        模板分区编号：<input id="subcode" type="text" class="input" disabled="disabled" runat="server"  />
        模板分区名称：<input id="subname" type="text" class="input" disabled="disabled" runat="server"/>
        占用行数：<input id="rows" type="text" class="input" runat="server"/>行X
        <input id="cows" type="text" class="input" runat="server"/>列
        <input type="button" value="1.生成座位平面图" class="button" onclick="SaveSeat();" />
        <input type="button" value="显示选中座位" class="button" onclick="SeatShow();" />
        <input type="button" value="隐藏选中座位" class="button" onclick="SeatHide();" />
        <input type="button" value="取消所有选择" class="button" onclick="SeatGet();" />
        
    </div>
    <div style="background-color: #ffffff; margin-top: 5px;">
        子分区<input id="Note" type="text" class="input" /><input type="button" value="设置" class="button"
            onclick="DrawNote();" />
        排号<input id="Row" type="text" class="input"  /><input type="button" value="设置" class="button"
            onclick="DrawRow();" />
        座号<input id="Cow" type="text" class="input" /><input type="button" value="设置" class="button"
            onclick="DrawCow();" />
        座位描述<input id="Msg" type="text" class="input" /><input type="button" value="设置" class="button"
            onclick="DrawMsg();" />
        颜色<input id="Color" imagepath="imgs/" type="text" class="input" />
        票类名称<input id="ticketname" type="text" class="input" />
        票类价格<input id="ticketprice" type="text" class="input" /><input type="button" value="设置"    class="button" onclick="DrawPriceColor();" />
            <input type="button" value="返回" class="button" onclick="history.go(-1);" />
    </div>
    <div id="WorkFlowSpan" style="width: 100%; background-color: #E7E7E7; margin-top: 10px;
        margin-bottom: 50px; text-align: center; font-size: 14px; position: relative;">
        <div id="Seats">
        </div>
    </div>
    <div id="dHTMLToolTip" style="position: absolute; visibility: hidden; width: 0; height: 0;
        z-index: 1000; left: 0; top: 0">
    </div>
    </form>
</body>
</html>
